package com.weipai.springboot.module.mapper;

import com.weipai.springboot.model.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;
import java.util.Map;

public interface OrderMapper {
    int deleteByPrimaryKey(String orderId);

    int insert(Order record);

    int insertSelective(Order record);

    Order selectByPrimaryKey(String orderId);

    int updateByPrimaryKeySelective(Order record);

    int updateByPrimaryKey(Order record);

    List<Map<String, Object>> getOrderList(@Param("shopId") String shopId,
                                           @Param("customerId") String customerId, @Param("status") Integer status,
                                           @Param("orderNumber") String orderId, @Param("startTime") String startTime,
                                           @Param("endTime") String endTime, @Param("start") Integer start,
                                           @Param("size") Integer size,
                                           @Param("keyword") String keyword,
                                           @Param("modeOfPayment") Integer modeOfPayment);

    int countOrderList(@Param("shopId") String shopId,
                       @Param("customerId") String customerId,
                       @Param("status") Integer status,
                       @Param("orderNumber") String orderNumber,
                       @Param("startTime") String startTime,
                       @Param("endTime") String endTime);

    int deleteOrder(@Param("orderNumber") String orderNumber);

    List<Map<String, Object>> getOrderCountList(@Param("time") String time);

    //个人中心 获取各个订单状态 数量
    List<Map<String, Object>> getOrderCountListByNum(@Param("customerId") String customerId);


    //根据订单号查询订单
    Map<String, Object> getOrderInfoByOrderNumber(String orderNumber);

    //获取换货界面的商品信息、地址信息
    Map<String,Object> getOrderInfoByOrderNumberAndGoodsId(@Param("orderNumber") String orderNumber, 
                                                           @Param("goodsId") String goodsId);

    //获得用户全部的子订单
    List<Map<String,Object>> orderSublistByCustomerId(@Param("customerId") String customerId, 
                                                      @Param("start") Integer start, 
                                                      @Param("end") Integer size, 
                                                      @Param("isAfterSale") Integer isAfterSale);


    List<Map<String,Object>> orderSublistByCustomerIdForWeb(@Param("customerId") String customerId,
                                                            @Param("start") Integer start,
                                                            @Param("end") Integer size,
                                                            @Param("isAfterSale") Integer isAfterSale,
                                                            @Param("keyword") String keyword);

    //获得用户全部子订单的数量
    Integer orderSublistByCustomerIdAmount(@Param("customerId") String customerId, 
                                           @Param("isAfterSale") Integer isAfterSale);

    //点击售后申请跳转选择售后类型页面
    Map<String,Object> afterSaleTypeInfo(String orderSublistId);

    //确认发货
    @Update("update c_order set express_company=#{logisticsCompany}, courier_number=#{trackingNumber}, delivery_time = now(), order_status=3 " +
            "where order_number=#{orderNumber}")
    int confirmDelivery(@Param("orderNumber") String orderNumber,
                        @Param("logisticsCompany") String logisticsCompany,
                        @Param("trackingNumber") String trackingNumber);

    //更改订单状态
    int updatePaymentAndStatus(@Param("orderNumber") String orderNumber, @Param("payment") Integer payment,
                                @Param("orderStatus") int orderStatus, @Param("paymentStatus") int paymentStatus);


    //查询总共的交易金额
    Integer getAllRealPay(@Param("startTime") String startTime, @Param("endTime") String endTime);

    //按月份和订单状态分组查出交易金额
    List<Map<String,Object>> orderStatement(@Param("time") String time);

    int getOrderByShopId(@Param("shopId") String shopId);
    
    Order getOrderInfoByOrderNumber22(String orderNumber);

    //查询用户的下单金额和交易成功的金额
    Map<String,Object> getOrderAmountByCustomerId(@Param("customerId") String customerId,
                                                  @Param("status") int status);

    //根据订单的状态获取相应的订单
    List<Map<String,Object>> getOrderListByOrderStatus(int orderStatus);

    //更改订单状态为交易成功
    @Update("update c_order set order_status=#{orderStatus}, success_time = now() where order_number=#{orderNumber}")
    int updateOrderStatus(@Param("orderNumber") String orderNumber, @Param("orderStatus") int orderStatus);

    //更改订单的状态
    @Update("update c_order set order_status=#{orderStatus} where order_number=#{orderNumber}")
    int changeOrderStatus(@Param("orderNumber") String orderNumber, @Param("orderStatus") int status);


    //对外接口  返回客户订单信息
    List<Map<String,Object>> getOrderMessage();

    //查询用户订单每条订单退款金额
    List<Map<String, Object>> getOrderByMoney(@Param("customerId") String customerId);


}